#!/usr/bin/env python2
# license removed for brevity

#发布图像  opencv采集相机数据
import rospy
from std_msgs.msg import Image
import gxipy as gx
from cv_bridge import CvBridge,CvBridgeError
import cv2

cap=cv2.VideoCapture(0)
bridge=CvBridge()

def talker():
    pub = rospy.Publisher('/webcam', Image, queue_size=1)
    rospy.init_node('talker', anonymous=False)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        ret,frame = cap.read()
        if not ret:
            break
        msg=bridge.cv2_to_imgmsg(frame,"bgr8")
        pub.publish(msg)

        if cv2.waitKey(1) & 0xFF==ord('q'):
            break
        if rospy.is_shutdown():
            cap.release()
        

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass
